package com.hitqz.robot.biz.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.*;

@Configuration
public class BizThreadPoolConfig {

    @Bean("customThreadPool")
    public ExecutorService customThreadPool() {
        return new ThreadPoolExecutor(
                20,
                100,
                10L,
                TimeUnit.SECONDS,
                new LinkedBlockingQueue<>(100),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.AbortPolicy()
        );
    }

    @Bean("videoPushThreadPool")
    public ThreadPoolExecutor videoPushThreadPool() {
        return new ThreadPoolExecutor(
                50,
                200,
                1L,
                TimeUnit.SECONDS,
                new LinkedBlockingQueue<>(50),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.DiscardOldestPolicy()
        );
    }

    @Bean("websocketSendThreadPool")
    public ExecutorService websocketSendThreadPool() {
        return new ThreadPoolExecutor(
                50,
                200,
                200L,
                TimeUnit.MILLISECONDS,
                new LinkedBlockingQueue<>(50),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.DiscardOldestPolicy()
        );
    }


    @Bean("sseSendThreadPool")
    public ExecutorService sseSendThreadPool() {
        return new ThreadPoolExecutor(
                50,
                200,
                200L,
                TimeUnit.MILLISECONDS,
                new LinkedBlockingQueue<>(50),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.DiscardOldestPolicy()
        );
    }


}
